package net.llz.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.llz.enums.CouponCategoryEnum;
import net.llz.exception.BizException;
import net.llz.request.NewUserCouponRequest;
import net.llz.service.CouponService;
import net.llz.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Let-凡
 * @since 2023-01-15
 */
@RestController
@Api(tags = "优惠卷模块")
@RequestMapping("api/coupon/v1")
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 分页接口
     * @param page
     * @param size
     * @return
     */
    @ApiOperation("优惠卷分页查询")
    @GetMapping("page_coupon")
    public JsonData pageCouponList(
            @ApiParam(value = "当前页") @RequestParam(value = "page",defaultValue = "1") int page,
            @ApiParam(value = "每页多少条") @RequestParam(value = "size",defaultValue = "10") int size
    ){

        Map<String,Object>pageMap = couponService.pageCouponActivity(page,size);

        return JsonData.buildSuccess(pageMap);
    }

    @ApiOperation("添加优惠卷")
    @GetMapping("add/promotion/{coupon_id}")
    public JsonData addPromotionCoupon(@ApiParam(value = "优惠卷id",required = true)
                                       @PathVariable("coupon_id") long couponId) throws BizException {

        JsonData jsonData = couponService.addCoupon(couponId, CouponCategoryEnum.PROMOTION);
        return jsonData.buildSuccess();
    }


    @ApiOperation("新人领卷")
    @PostMapping("/new_user_coupon")
    public JsonData addNewUserCoupon(@ApiParam(value = "用户对象") @RequestBody NewUserCouponRequest newUserCouponRequest){

        JsonData jsonData = couponService.initNewUserCoupon(newUserCouponRequest);

        return jsonData;
    }


}

